// MAP relative
var geolocation;
var map = new AMap.Map('container',{
	resizeEnable:true,
	zoom:18,
	center:[104.048022,30.645217]
});
var marker = null;
//记录当前所有点
var markers = [];
/*古槐 碧草园 过厅 英武廊*/

map.on('click',function(e){
	var lng = e.lnglat.getLng();
	var lat = e.lnglat.getLat(); 
	for(var i = 0;i<spots.length;i++){
		if( (Math.abs(lng - spots[i].longitude ) < 0.00008) & (Math.abs(lat-spots[i].latitude ) < 0.00008) ){
			console.log(i);
			//点击到景点
			addMarker(lng,lat,"");
			popup_detail(spots[i].id)
			break;
		}
		else{				
				if(marker){
					marker.setMap(null);
					marker = null;
			}
		}				
	} 
}
);
function popup_detail(id) {
	Zepto.popup(".popup-detail")
	$('.popup').css("-webkit-transform","translate3d(0, 50%, 0)")
	$('.popup').css("transform","translate3d(0, 50%, 0)")
	getSpotDetail(uuid,id);
}
function addMarker(addLng,addLat,title) {
	if(marker) { return; }
    marker = new AMap.Marker({
        icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
        position: [addLng, addLat]
       /* draggable:true,        //备用
        cursor:'move',
        raiseOnDrag:true */
    });
    marker.setMap(map);
    marker.setTitle(title);
}

function makeMap(points){
	for(var i = 0;i<points.length;i++){
		var mapMarker = new AMap.Marker({
        	icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
        	position: [points[i].longitude, points[i].latitude]
    	});
    	mapMarker.setMap(map);  
    	console.log(points[i].name);
    	mapMarker.setLabel({
    		content:points[i].name,
    		offset: new AMap.Pixel(-15, -40),
    	});
    	markers.push(mapMarker);
    }
}
 function removePoint() {
   	var features = [];
   	features.push("bg");
   	features.push("road");
   	features.push("building");
    map.setFeatures(features);
}
// map.plugin('AMap.Geolocation', function() {
//     geolocation = new AMap.Geolocation({
//         enableHighAccuracy: true,//是否使用高精度定位，默认:true
//         timeout: 10000,          //超过10秒后停止定位，默认：无穷大
//         buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
//         zoomToAccuracy: false,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
//         buttonPosition:'RB'
//     });
//     //map.addControl(geolocation);
//     geolocation.getCurrentPosition();
//     AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
//     AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
// });
// //解析定位结果
// function onComplete(data) {
//     var str=['定位成功'];
//     str.push('经度：' + data.position.getLng());
//     str.push('纬度：' + data.position.getLat());
//     str.push('精度：' + data.accuracy + ' 米');
//     str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
//     //alert("str:" + str);
// }
// //解析定位错误信息
// function onError(data) {
//     //alert("str:" + data);
// }


